package com.ysd.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.ysd.entity.User;
import com.ysd.repository.UserRepository;
import com.ysd.util.Result;

@RestController
public class UserController {
		@Autowired
		private UserRepository repository;
		@RequestMapping("loginUser")
		public Object loginUser(String userName, String password,User user,HttpSession session) {
			Map<String, Object> map = new HashMap<String,Object>();
			User u=	 repository.findByUserNameAndPassword(userName, password);
			System.out.println(u);
			if (u!=null) {
				if (u.getPassword().equals(password)) {
					session.setAttribute("user", user);
					//return map.put("登陆成功", true);
					return Result.toClient("0", "登陆成功", null, u);
				} else {
					return Result.toClient("1", "账号或密码错误！", null, null);
					//return map.put("账号或密码错误", false);
				}
			}else {
				return Result.toClient("1", "账号或密码错误！", null, null);
				//return map.put("账号或密码错误", false);
			}
			
		}
}
